<?
require_once ("jpgraph.php");
require_once("jpgraph_line.php");
require_once("inc.member.php");

$datax=array(); 
$datay=array(); 
$datay2=array(); 
$datay3=array(); 

$strsq1="SELECT buy_price, date_format(buy_date,'%Y-%m-%d') as buy_date FROM `gg_share` group by buy_price order by buy_price,buy_date";
$rs = mysql_query($strsq1);	

array_push($datay,'0.0');
array_push($datax,'2011-02-01');	
$new_date = '2011-02-01';

while ($share = mysql_fetch_assoc($rs)) {	
	
	if($new_date == $share["buy_date"]){
		array_pop($datay);
		array_push($datay,number_format($share["buy_price"],2));
	}else{
		array_push($datay,number_format($share["buy_price"],2));
		array_push($datax,$share["buy_date"]);
		$new_date = $share["buy_date"];
	}
	
	//array_push($datay,number_format($share["buy_price"],2));
	//array_push($datax,$share["buy_date"]);
}

for($i=count($datay);$i>8; $i--){
	array_shift($datay);
	array_shift($datax);
}

$graph = new Graph(650,350,"auto");
$graph->img->SetMargin(70,40,40,40);	

$graph->img->SetAntiAliasing();
$graph->SetScale("textlin",0,$share["buy_price"]);
$graph->SetShadow();
$graph->title->Set("Cash Flow Point Chart");
$graph->title->SetFont(FF_FONT1, FS_NORMAL);

$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->title->SET("Date");
$graph->xaxis->title->SetFont(FF_FONT1, FS_NORMAL);
$graph->xaxis->title->SetMargin(4);

$graph->yaxis->title->SET("Cash Flow Point");
$graph->yaxis->title->SetFont(FF_FONT1, FS_NORMAL);
$graph->yaxis->title->SetMargin(5);
$graph->ygrid->SetFill(false);
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->yaxis->HideZeroLabel();


//$graph->SetY2Scale("lin");
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->Pos(0.5,0.5,"center","center");

// Add grace to top and bottom of plot
$graph->yscale->SetGrace(0,0);
$p1 = new LinePlot($datay);
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("teal");
$p1->mark->SetWidth(3);
$p1->value->SetFormat('%01.2f');
$p1->value->Show();
$p1->SetColor("teal");
$p1->SetCenter();

$graph->Add($p1);

$graph->Stroke();
?>